package sdau.hjk.service.Impl;

import sdau.hjk.dao.IManagerDao;
import sdau.hjk.dao.IUserDao;
import sdau.hjk.dao.IUserRecordDao;
import sdau.hjk.dao.IUserReportDao;
import sdau.hjk.entity.Manager;
import sdau.hjk.entity.User;
import sdau.hjk.entity.UserRecord;
import sdau.hjk.entity.UserReport;
import sdau.hjk.service.IManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sdau.hjk.util.EncryptionUtils;

import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 *@version 1.0
 *@author: huangjiakai
 *@create:2021−03-01 19:03
 *@className:com.hjk.service.Impl.ManagerService
 *@description: TODO
 */
@Service("managerService")
public class ManagerService implements IManagerService {
    @Autowired
    private IManagerDao managerDao;
    @Autowired
    private IUserReportDao userReportDao;
    @Autowired
    private IUserDao userDao;
    @Autowired
    private IUserRecordDao userRecordDao;

    @Override
    public Manager find(String name, String password) {
        String ps = EncryptionUtils.md5(password);
        return managerDao.find(name,ps);
    }

    @Override
    public List<UserReport> findAllReport() {
        return userReportDao.findAllReport();
    }

    @Override
    public void approveUserReport(UserReport userReport) {
        userReportDao.approveUserReport(userReport);
    }

    @Override
    public List<User> findByMajor(String major) {
        return userDao.findByMajor(major);
    }

    @Override
    public List<UserRecord> findByNote() throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Date date =calendar.getTime();
        String dateStringParse = sdf.format(date);
        Date dateParse = sdf.parse(dateStringParse);
        return userRecordDao.findByNote(dateParse);
    }

    @Override
    public List<User> findByNotClock() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Date date =calendar.getTime();
        String dateStringParse = sdf.format(date);
        Date dateParse = sdf.parse(dateStringParse);
        return userRecordDao.findByNotClock(dateParse);
    }

    @Override
    public void deleteUser(Integer id) {
        userDao.deleteUser(id);
        userDao.deleteUserInfo(id);
    }


}
